package com.tancire.sources.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.sources.domain.SurTags;
import com.tancire.sources.service.ISurTagsService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 资源标签Controller
 *
 * @author chenchao
 * @date 2024-07-28
 */
@RestController
@RequestMapping("/sources/tags")
public class SurTagsController extends BaseController {
    @Resource
    private ISurTagsService surTagsService;

    /**
     * 查询资源标签列表
     */
    @PreAuthorize("@ss.hasPermi('sources:tags:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurTags surTags) {
        startPage();
        List<SurTags> list = surTagsService.selectSurTagsList(surTags);
        return getDataTable(list);
    }

    /**
     * 导出资源标签列表
     */
    @PreAuthorize("@ss.hasPermi('sources:tags:export')")
    @Log(title = "资源标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurTags surTags) {
        List<SurTags> list = surTagsService.selectSurTagsList(surTags);
        ExcelUtil<SurTags> util = new ExcelUtil<SurTags>(SurTags.class);
        util.exportExcel(response, list, "资源标签数据");
    }

    /**
     * 获取资源标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('sources:tags:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(surTagsService.selectSurTagsById(id));
    }

    /**
     * 新增资源标签
     */
    @PreAuthorize("@ss.hasPermi('sources:tags:add')")
    @Log(title = "资源标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurTags surTags) {
        return toAjax(surTagsService.insertSurTags(surTags));
    }

    /**
     * 修改资源标签
     */
    @PreAuthorize("@ss.hasPermi('sources:tags:edit')")
    @Log(title = "资源标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurTags surTags) {
        return toAjax(surTagsService.updateSurTags(surTags));
    }

    /**
     * 删除资源标签
     */
    @PreAuthorize("@ss.hasPermi('sources:tags:remove')")
    @Log(title = "资源标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(surTagsService.deleteSurTagsByIds(ids));
    }
}
